www.gusucode.com > 超声波测量以及形成图像 对相关信号进行模拟仿真 > 超声波测量以及形成图像 对相关信号进行模拟仿真/digital holograpy/dh/dd_window.m

    function varargout = dd_window(varargin)
% DD_WINDOW M-file for dd_window.fig
%      DD_WINDOW, by itself, creates a new DD_WINDOW or raises the existing
%      singleton*.
%
%      H = DD_WINDOW returns the handle to a new DD_WINDOW or the handle to
%      the existing singleton*.
%
%      DD_WINDOW('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DD_WINDOW.M with the given input arguments.
%
%      DD_WINDOW('Property','Value',...) creates a new DD_WINDOW or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before dd_window_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to dd_window_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help dd_window

% Last Modified by GUIDE v2.5 02-Jan-2008 21:06:35

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @dd_window_OpeningFcn, ...
                   'gui_OutputFcn',  @dd_window_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before dd_window is made visible.
function dd_window_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to dd_window (see VARARGIN)
axes(handles.reconim_axes)
imagesc(ones(576,768)),colormap(gray);
axis equal tight;

set(handles.history_lbox,'String',cell(1,0),'value',1);

set(handles.dx_edit,'string','0.0086');
set(handles.dy_edit,'string','0.0083');
set(handles.lambda_edit,'string','532');

handles.initialhwp.M=576;
handles.initialhwp.N=768;
handles.initialhwp.dx=0.0086;
handles.initialhwp.dy=0.0083;
handles.initialhwp.lambda=532;
handles.initialdist=[];

handles.vs=1;
handles.ondisp=[];
handles.hologram=[];
handles.recons=[];
handles.focusquality.difference=[];
handles.focusquality.gradient=[];
handles.focusquality.sobel=[];
handles.focusquality.variance=[];
handles.area=[1,768,1,576];
handles.lastmethod=1;

if nargin > 4
    for n=1:2:length(varargin)
        if strcmpi(varargin{n},'hwp')
            hwp=varargin{n+1};
            set(handles.dx_edit,'string',num2str(hwp.dx));
            set(handles.dy_edit,'string',num2str(hwp.dy));
            set(handles.lambda_edit,'string',num2str(hwp.lambda));
            handles.initialhwp=hwp;
        end
        if strcmpi(varargin{n},'hologram')
            handles.hologram=varargin{n+1};
            [M,N]=size(handles.hologram);
            handles.area=[1,N,1,M];
        end
        if strcmpi(varargin{n},'dist')
            dist=varargin{n+1};
            if ~isempty(dist)
                set(handles.setdistx_edit,'string',num2str(dist(1)));
                set(handles.setdisty_edit,'string',num2str(dist(2)));
                set(handles.distvector_edit,'string',[num2str(mean(dist)-50),':5:',num2str(mean(dist)+50)]);
                handles.initialdist=dist;
            end
        end
    end
end

% Choose default command line output for dd_window
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes dd_window wait for user response (see UIRESUME)
uiwait(handles.dd_window);


% --- Outputs from this function are returned to the command line.
function varargout = dd_window_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
if isempty(findobj('type','figure','tag','dd_window'))
    switch nargout
        case 1
            varargout{1}=[];
        case 2
            varargout{1}=[];
            varargout{2}=[];
    end
    return
end

switch get(handles.done_button,'enable')
    case 'on'
        hwp=[];
        dist=[];
    case 'off'
        distx=str2num(get(handles.setdistx_edit,'string'));
        disty=str2num(get(handles.setdisty_edit,'string'));
        dx=str2num(get(handles.dx_edit,'string'));
        dy=str2num(get(handles.dy_edit,'string'));
        lambda=str2num(get(handles.lambda_edit,'string'));
        
        if ~isempty(handles.hologram)
            [M,N]=size(handles.hologram);
        else
            M=handles.initialhwp.M;
            N=handles.initialhwp.N;
        end
        
        if isempty(dx)
            dx=handles.initialhwp.dx;
        end
        if isempty(dy)
            dy=handles.initialhwp.dy;
        end
        if isempty(lambda)
            lambda=handles.initialhwp.lambda;
        end
        hwp.M=M;
        hwp.N=N;
        hwp.dx=dx;
        hwp.dy=dy;
        hwp.lambda=lambda;

        if isempty(distx) || isempty(disty)
            dist=handles.initialdist;
        else
            dist=[distx,disty];
        end
end

switch nargout
    case 1
        varargout{1}=dist;
    case 2
        varargout{1}=dist;
        varargout{2}=hwp;
end
delete(handles.dd_window)


% --- Executes during object creation, after setting all properties.
function history_lbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to history_lbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in history_lbox.
function history_lbox_Callback(hObject, eventdata, handles)
% hObject    handle to history_lbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns history_lbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from history_lbox
if strcmp(get(handles.dd_window,'SelectionType'),'open')
    items=get(handles.history_lbox,'string');
    index=get(handles.history_lbox,'value');
    if isempty(items)
        return
    end
    v=get(handles.slider,'value');
    axes(handles.reconim_axes)
    imagesc(handles.area(1):handles.area(2),handles.area(3):handles.area(4),...
        (handles.recons(:,:,index)).^v),colormap(gray);
    axis equal tight;
    dist=str2num(items{index}(3:end));
    set(handles.setdistx_edit,'string',num2str(dist(1)))
    set(handles.setdisty_edit,'string',num2str(dist(2)))
    handles.ondisp=index;
end


% --- Executes during object creation, after setting all properties.
function setdistx_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to setdistx_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function setdistx_edit_Callback(hObject, eventdata, handles)
% hObject    handle to setdistx_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of setdistx_edit as text
%        str2double(get(hObject,'String')) returns contents of setdistx_edit as a double
if get(handles.link_check,'value')==get(handles.link_check,'max')
    set(handles.setdisty_edit,'string',get(handles.setdistx_edit,'string'))
end


% --- Executes during object creation, after setting all properties.
function setdisty_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to setdisty_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function setdisty_edit_Callback(hObject, eventdata, handles)
% hObject    handle to setdisty_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of setdisty_edit as text
%        str2double(get(hObject,'String')) returns contents of setdisty_edit as a double
if get(handles.link_check,'value')==get(handles.link_check,'max')
    set(handles.setdistx_edit,'string',get(handles.setdisty_edit,'string'))
end


% --- Executes on button press in link_check.
function link_check_Callback(hObject, eventdata, handles)
% hObject    handle to link_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of link_check


% --- Executes on button press in reset_button.
function reset_button_Callback(hObject, eventdata, handles)
% hObject    handle to reset_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.reconim_axes)
imagesc(ones(576,768)),colormap(gray);
axis equal tight;

axes(handles.autofocus_axes)
cla

set(handles.history_lbox,'String',cell(1,0),'value',1)
set(handles.slider,'value',1)
set(handles.link_check,'value',get(handles.link_check,'min'))
set(handles.areaok_button,'enable','on');
set(handles.dx_edit,'enable','on')
set(handles.dy_edit,'enable','on')
set(handles.lambda_edit,'enable','on')
set(handles.plot_button,'enable','off')
set(handles.method,'value',1);

set(handles.dx_edit,'string',num2str(handles.initialhwp.dx));
set(handles.dy_edit,'string',num2str(handles.initialhwp.dy));
set(handles.lambda_edit,'string',num2str(handles.initialhwp.lambda));
if isempty(handles.initialdist)
    set(handles.setdistx_edit,'string','');
    set(handles.setdisty_edit,'string','');
    set(handles.distvector_edit,'string','');
else
    set(handles.setdistx_edit,'string',num2str(handles.initialdist(1)));
    set(handles.setdisty_edit,'string',num2str(handles.initialdist(2)));
    set(handles.distvector_edit,'string',[num2str(mean(handles.initialdist)-50),...
            ':5:',num2str(mean(handles.initialdist)+50)]);
end

if isempty(handles.hologram)
    handles.area=[1,768,1,576];
else
    [M,N]=size(handles.hologram);
    handles.area=[1,N,1,M];
end

handles.vs=1;
handles.ondisp=[];
handles.recons=[];
handles.focusquality.difference=[];
handles.focusquality.gradient=[];
handles.focusquality.sobel=[];
handles.focusquality.variance=[];
handles.lastmethod=1;

guidata(hObject,handles)


% --- Executes on button press in disp_button.
function disp_button_Callback(hObject, eventdata, handles)
% hObject    handle to disp_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isempty(handles.hologram)
    return
end
distx=str2num(get(handles.setdistx_edit,'string'));
disty=str2num(get(handles.setdisty_edit,'string'));
dx=str2num(get(handles.dx_edit,'string'));
dy=str2num(get(handles.dy_edit,'string'));
lambda=str2num(get(handles.lambda_edit,'string'));
if isempty(distx) || isempty(disty) || isempty(dx)...
        || isempty(dy) || isempty(lambda)
    return
end

v=get(handles.slider,'value');

if strcmp(get(handles.areaok_button,'enable'),'on')
    handles.recons=zero2one(abs(fresnel(handles.hologram,-[distx,disty],[dx,dy],lambda*1e-6)));
    axes(handles.reconim_axes)
    imagesc((handles.recons).^v),colormap(gray);
    handles.ondisp=1;
    axis equal tight;
else
    items=get(handles.history_lbox,'string');
    str=['d=[',num2str(distx),',',num2str(disty),']'];
    lgc=strcmp(items,str);
    m=length(lgc);
    ind=find(lgc);
    if isempty(ind)
        temp=zero2one(abs(fresnel(handles.hologram,-[distx,disty],[dx,dy],lambda*1e-6)));
        temp=temp(handles.area(3):handles.area(4),handles.area(1):handles.area(2));
        axes(handles.reconim_axes)
        imagesc(handles.area(1):handles.area(2),handles.area(3):handles.area(4),temp.^v),colormap(gray);
        axis equal tight;
        if m<10
            handles.recons(:,:,m+1)=temp;
            items{m+1}=str;
            set(handles.history_lbox,'string',items);
            set(handles.history_lbox,'value',m+1);
            handles.ondisp=m+1;
        else
            handles.recons(:,:,1)=[];
            items(1)=[];
            handles.recons(:,:,10)=temp;
            items{10}=str;
            set(handles.history_lbox,'string',items);
            set(handles.history_lbox,'value',10);
            handles.ondisp=10;
        end
    else
        set(handles.history_lbox,'value',ind);
        axes(handles.reconim_axes)
        imagesc(handles.area(1):handles.area(2),handles.area(3):handles.area(4),...
            (handles.recons(:,:,ind)).^v),colormap(gray);
        axis equal tight;
        handles.ondisp=ind;
    end
end

handles.lastdistx=distx;
handles.lastdisty=disty;
guidata(hObject,handles)


% --- Executes on button press in areaok_button.
function areaok_button_Callback(hObject, eventdata, handles)
% hObject    handle to areaok_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isempty(handles.ondisp)
    set(handles.plot_button,'enable','on')
    set(handles.areaok_button,'enable','off')
    set(handles.range_button,'enable','off')
    set(handles.dx_edit,'enable','off')
    set(handles.dy_edit,'enable','off')
    set(handles.lambda_edit,'enable','off')
    handles.vs=get(handles.slider,'value');
    guidata(hObject,handles)
    return
end

[M,N]=size(handles.hologram);
x=round(get(handles.reconim_axes,'xlim'));
y=round(get(handles.reconim_axes,'ylim'));

if x(1)>N || x(2)<1 || y(1)>M || y(2)<1
    return
end

if x(1)<1
    x(1)=1;
end
if x(2)>N
    x(2)=N;
end
if y(1)<1
    y(1)=1;
end
if y(2)>M
    y(2)=M;
end

handles.area=[x,y];
handles.recons=handles.recons(y(1):y(2),x(1):x(2));
handles.ondisp=1;
handles.vs=get(handles.slider,'value');

v=get(handles.slider,'value');
axes(handles.reconim_axes);
imagesc(x(1):x(2),y(1):y(2),(handles.recons).^v),colormap(gray);
axis equal tight;

set(handles.plot_button,'enable','on')
set(handles.areaok_button,'enable','off')
set(handles.range_button,'enable','off')
set(handles.history_lbox,'string',{['d=[',num2str(handles.lastdistx),',',num2str(handles.lastdisty),']']})
set(handles.history_lbox,'value',1)
set(handles.dx_edit,'enable','off')
set(handles.dy_edit,'enable','off')
set(handles.lambda_edit,'enable','off')

guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function distvector_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to distvector_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function distvector_edit_Callback(hObject, eventdata, handles)
% hObject    handle to distvector_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of distvector_edit as text
%        str2double(get(hObject,'String')) returns contents of distvector_edit as a double


% --- Executes on button press in plot_button.
function plot_button_Callback(hObject, eventdata, handles)
% hObject    handle to plot_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
newdist=str2num(get(handles.distvector_edit,'string'));
if isempty(newdist) || isempty(handles.hologram)
    return
end

dx=str2num(get(handles.dx_edit,'string'));
dy=str2num(get(handles.dy_edit,'string'));
lambda=str2num(get(handles.lambda_edit,'string'));
items=get(handles.method,'string');
index=get(handles.method,'value');

N=0;
for dist=newdist
    if isempty(handles.focusquality.(items{index})) || ~sum(handles.focusquality.(items{index})(:,1)==dist)
        N=N+1;
    end
end

if N>1
    h=waitbar(0,'Calculating...');
end

n=0;
for dist=newdist
    if isempty(handles.focusquality.(items{index})) || ~sum(handles.focusquality.(items{index})(:,1)==dist)
        temp=zero2one(abs(fresnel(handles.hologram,-dist,[dx,dy],lambda*1e-6)));
        temp=temp(handles.area(3):handles.area(4),handles.area(1):handles.area(2));
        temp=temp.^handles.vs;
        temp=temp./sum(sum(temp));
        switch index
            case 1
                gx=sum(sum(abs(temp(2:end,2:end)-temp(2:end,1:end-1))));
                gy=sum(sum(abs(temp(2:end,2:end)-temp(1:end-1,2:end))));
            case 2
                [gx,gy] = gradient(temp);
                gx=sum(sum(abs(gx)));
                gy=sum(sum(abs(gy)));
            case 3
                gx=sum(sum(abs(filter2([-1,0,1;-2,0,2;-1,0,1]/8,temp,'same'))));
                gy=sum(sum(abs(filter2([1,2,1;0,0,0;-1,-2,-1]/8,temp,'same'))));
            case 4
                gx=mean(var(temp'));
                gy=mean(var(temp));
        end
        handles.focusquality.(items{index}) = [handles.focusquality.(items{index});[dist,gx,gy]];
        n=n+1;
        if N>1
            waitbar(n/N,h);
        end
    end
end
if N>1
    close(h);
end
handles.focusquality.(items{index})=sortrows(handles.focusquality.(items{index}),1);
reset(handles.autofocus_axes)
axes(handles.autofocus_axes)
plot(handles.focusquality.(items{index})(:,1),zero2one(handles.focusquality.(items{index})(:,2)),'-b');
hold on
plot(handles.focusquality.(items{index})(:,1),zero2one(handles.focusquality.(items{index})(:,3)),'-g');
legend('x','y',4);
xlabel('Reconstruction distance (mm)');
ylabel('Focusing quality');

[cx,indx]=max(handles.focusquality.(items{index})(:,2));
[cy,indy]=max(handles.focusquality.(items{index})(:,3));
set(handles.setdistx_edit,'string',num2str(handles.focusquality.(items{index})(indx,1)))
set(handles.setdisty_edit,'string',num2str(handles.focusquality.(items{index})(indy,1)))

guidata(hObject,handles)


% --- Executes during object creation, after setting all properties.
function slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider_Callback(hObject, eventdata, handles)
% hObject    handle to slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
if isempty(handles.ondisp)
    return
end
v=get(handles.slider,'value');
axes(handles.reconim_axes);
imagesc(handles.area(1):handles.area(2),handles.area(3):handles.area(4),...
    (handles.recons(:,:,handles.ondisp)).^v),colormap(gray);
axis equal tight;


% --- Executes during object creation, after setting all properties.
function dx_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dx_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function dx_edit_Callback(hObject, eventdata, handles)
% hObject    handle to dx_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dx_edit as text
%        str2double(get(hObject,'String')) returns contents of dx_edit as a double


% --- Executes during object creation, after setting all properties.
function dy_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dy_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function dy_edit_Callback(hObject, eventdata, handles)
% hObject    handle to dy_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dy_edit as text
%        str2double(get(hObject,'String')) returns contents of dy_edit as a double


% --- Executes during object creation, after setting all properties.
function lambda_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to lambda_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function lambda_edit_Callback(hObject, eventdata, handles)
% hObject    handle to lambda_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of lambda_edit as text
%        str2double(get(hObject,'String')) returns contents of lambda_edit as a double


% --- Executes on button press in done_button.
function done_button_Callback(hObject, eventdata, handles)
% hObject    handle to done_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(get(handles.dd_window, 'waitstatus'), 'waiting')
    set(handles.done_button,'enable','off')
    uiresume(handles.dd_window);
end


% --- Executes when user attempts to close dd_window.
function dd_window_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to dd_window (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
if isequal(get(handles.dd_window, 'waitstatus'), 'waiting')
    % The GUI is still in UIWAIT, us UIRESUME
    uiresume(handles.dd_window);
else
    % The GUI is no longer waiting, just close it
    delete(handles.dd_window);
end


% --- Executes during object creation, after setting all properties.
function method_CreateFcn(hObject, eventdata, handles)
% hObject    handle to method (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in method.
function method_Callback(hObject, eventdata, handles)
% hObject    handle to method (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns method contents as cell array
%        contents{get(hObject,'Value')} returns selected item from method
items=get(hObject,'string');
index=get(hObject,'value');

if handles.lastmethod==index || isempty(handles.focusquality.(items{index}))
    return
else
    reset(handles.autofocus_axes)
    axes(handles.autofocus_axes)
    plot(handles.focusquality.(items{index})(:,1),zero2one(handles.focusquality.(items{index})(:,2)),'-b');
    hold on
    plot(handles.focusquality.(items{index})(:,1),zero2one(handles.focusquality.(items{index})(:,3)),'-g');
    legend('x','y',4);
    xlabel('Reconstruction distance (mm)');
    ylabel('Focusing quality');
end

handles.lastmethod=index;
guidata(hObject,handles)


% --- Executes on button press in range_button.
function range_button_Callback(hObject, eventdata, handles)
% hObject    handle to range_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.reconim_axes)
[x,y] = ginput(2);
if isempty(x) || isempty(y)
    return
end
x=sort(x);
y=sort(y);

set(handles.reconim_axes,'xlim',x)
set(handles.reconim_axes,'ylim',y)